var  http = require('http')
var url = require('url')

var server = http.createServer()

server.on('request',function (req,res) {
    // console.log(req.url)                            // 访问路径

    var urlStr = url.parse(req.url);                   // 对url格式的字符串进行解析，返回一个对象
    // console.log(urlStr)

    switch (urlStr.pathname){
        case '/':
            res.writeHead(200,{
                'content-type':'text/html;charset=utf-8'
            });
            res.end('<h1>首页</h1>')
            break;
        
        case '/user':
            res.writeHead(200,{
                'content-type':'text/html;charset=utf-8'
            });
            res.end('<h1>个人中心</h1>')
            break;

        default:
            res.writeHead(404,{
                'content-type':'text/html;charset=utf-8'
            });
            res.end('<h1>地址有误</h1>')
            break;

    }
})

server.listen(8060, 'localhost')




